package com.hngates.architecture.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hngates.common.annotation.Log;
import com.hngates.common.enums.BusinessType;
import com.hngates.architecture.domain.ArcProjectBuilderRel;
import com.hngates.architecture.service.IArcProjectBuilderRelService;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.utils.poi.ExcelUtil;
import com.hngates.common.core.page.TableDataInfo;

/**
 * 工地与建设单位对应关系Controller
 * 
 * @author jwhe
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/architecture/projectBuilderRel")
public class ArcProjectBuilderRelController extends BaseController
{
    private String prefix = "architecture/projectBuilderRel";

    @Autowired
    private IArcProjectBuilderRelService arcProjectBuilderRelService;

    @RequiresPermissions("architecture:projectBuilderRel:view")
    @GetMapping()
    public String projectBuilderRel()
    {
        return prefix + "/projectBuilderRel";
    }

    /**
     * 查询工地与建设单位对应关系列表
     */
    @RequiresPermissions("architecture:projectBuilderRel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArcProjectBuilderRel arcProjectBuilderRel)
    {
        startPage();
        List<ArcProjectBuilderRel> list = arcProjectBuilderRelService.selectArcProjectBuilderRelList(arcProjectBuilderRel);
        return getDataTable(list);
    }

    /**
     * 导出工地与建设单位对应关系列表
     */
    @RequiresPermissions("architecture:projectBuilderRel:export")
    @Log(title = "工地与建设单位对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArcProjectBuilderRel arcProjectBuilderRel)
    {
        List<ArcProjectBuilderRel> list = arcProjectBuilderRelService.selectArcProjectBuilderRelList(arcProjectBuilderRel);
        ExcelUtil<ArcProjectBuilderRel> util = new ExcelUtil<ArcProjectBuilderRel>(ArcProjectBuilderRel.class);
        return util.exportExcel(list, "工地与建设单位对应关系数据");
    }

    /**
     * 新增工地与建设单位对应关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工地与建设单位对应关系
     */
    @RequiresPermissions("architecture:projectBuilderRel:add")
    @Log(title = "工地与建设单位对应关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArcProjectBuilderRel arcProjectBuilderRel)
    {
        return toAjax(arcProjectBuilderRelService.insertArcProjectBuilderRel(arcProjectBuilderRel));
    }

    /**
     * 修改工地与建设单位对应关系
     */
    @RequiresPermissions("architecture:projectBuilderRel:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ArcProjectBuilderRel arcProjectBuilderRel = arcProjectBuilderRelService.selectArcProjectBuilderRelById(id);
        mmap.put("arcProjectBuilderRel", arcProjectBuilderRel);
        return prefix + "/edit";
    }

    /**
     * 修改保存工地与建设单位对应关系
     */
    @RequiresPermissions("architecture:projectBuilderRel:edit")
    @Log(title = "工地与建设单位对应关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArcProjectBuilderRel arcProjectBuilderRel)
    {
        return toAjax(arcProjectBuilderRelService.updateArcProjectBuilderRel(arcProjectBuilderRel));
    }

    /**
     * 删除工地与建设单位对应关系
     */
    @RequiresPermissions("architecture:projectBuilderRel:remove")
    @Log(title = "工地与建设单位对应关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(arcProjectBuilderRelService.deleteArcProjectBuilderRelByIds(ids));
    }
}
